import axios from "axios";
export default ({
    namespaced: true,
    state: {
        currentPage: 1,
        pageSize: 3,
        idcard: "",
        lessor:1,
        pageData: {
            usersData: [],
            total: 0,
            pages: 0
        }
    },
    mutations: {
        getAllUsers(state, payload) {
            state.pageData = payload;
        },
        changePage(state, newcurrentPage) {
            state.currentPage = newcurrentPage;
        },
        changeSize(state, newpageSize) {
            state.pageSize = newpageSize;
        },
    },
    actions: {
        getAllUsersAsync(context) {
            const { currentPage, pageSize } = context.state;
            axios.get("/users/getAllUsers", { params: { currentPage, pageSize } }).then(res => {
                //调用mutations的方法
                context.commit("getAllUsers", res.data);
            })
        },
        //获取idcard为空(未实名的)
        getUnnamedUsersAsync(context) {
            const { currentPage, pageSize, idcard } = context.state;
            axios.get("/users/getUnnamedUsers", { params: { currentPage, pageSize, idcard } }).then(res => {
                //调用mutations的方法
                context.commit("getAllUsers", res.data);
            })
        },
        getUnpassUsersAsync(context) {
            const { currentPage, pageSize, lessor } = context.state;
            axios.get("/users/getUnpassUsers", { params: { currentPage, pageSize, lessor } }).then(res => {
                //调用mutations的方法
                context.commit("getAllUsers", res.data);
            })
        },
        changePageAsync(context, newcurrentPage) {
            context.commit('changePage', newcurrentPage)
            console.log(context.state.currentPage)
        },
        changeSizeAsync(context, newpageSize) {
            context.commit('changeSize', newpageSize)
            console.log(context.state.pageSize)
        },

    }
})